#!/usr/bin/python
#-*- coding:utf-8 -*-

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)


from pymongo import MongoClient

from settings import handlers,settings

class Application(tornado.web.Application):
    def __init__(self):      
        dbclient = MongoClient('localhost',27017)
        self.db = dbclient.blog
        tornado.web.Application.__init__(self, handlers, **settings)
    
if __name__=="__main__":
    tornado.options.parse_command_line()    
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()